# -*- coding:utf-8 -*-
# @author='dapeng'
# @version='1.0.0'
#天行api https://www.tianapi.com
import urllib.request
import urllib.parse
import json
import configparser

cf = configparser.ConfigParser()
cf.read("D:/Program Files/pycharm/wechat-robot/configuration/config.ini")  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块

key = cf.get("Tianxing", "appkey")

#文案
def topic():
    url = 'http://api.tianapi.com/txapi/pyqwenan/index?key=%s'%key
    f = urllib.request.urlopen(url)
    result = json.loads(f.read().decode('utf-8'))
    res = result.get('newslist')[0].get('content')
    return res


#互删狠话
def delete():
    url = 'http://api.tianapi.com/txapi/hsjz/index?key=%s'%key
    f = urllib.request.urlopen(url)
    result = json.loads(f.read().decode('utf-8'))
    res = result.get('newslist')[0].get('content')
    return res


#脑筋急转弯
def naowan():
    url = 'http://api.tianapi.com/txapi/naowan/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('quest')
    result = resp.get('newslist')[0].get('result')
    return req + '\r\n' + result


#经典台词
def dialogue():
    url = 'http://api.tianapi.com/txapi/dialogue/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('dialogue')
    return result


#彩虹屁
def caihongpi():
    url = 'http://api.tianapi.com/txapi/caihongpi/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('content')
    return result


#猜字谜
def zimi():
    url = 'http://api.tianapi.com/txapi/zimi/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('content')
    result = resp.get('newslist')[0].get('reason')
    return req+ '\r\n'+result


#猜成语
def caichengyu():
    url = 'http://api.tianapi.com/txapi/caichengyu/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('question')
    result = resp.get('newslist')[0].get('answer')
    return req+ '\r\n'+result


#猜广告语
def slogan():
    url = 'http://api.tianapi.com/txapi/slogan/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('content')
    result = resp.get('newslist')[0].get('answer')
    return req+ '\r\n'+result


#故事
def story():
    url = 'http://api.tianapi.com/txapi/story/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('title')
    result = resp.get('newslist')[0].get('content')
    return req+ '\r\n'+result


#舔狗日记
def tiangou():
    url = 'http://api.tianapi.com/txapi/tiangou/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('content')
    return result


#绕口令
def rkl():
    url = 'http://api.tianapi.com/txapi/rkl/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('content').replace('<br/>','\r\n')
    return result


#土情话
def saylove():
    url = 'http://api.tianapi.com/txapi/saylove/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('content').replace('<br/>','\r\n')
    return result



#顺口溜
def skl():
    url = 'http://api.tianapi.com/txapi/skl/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    result = resp.get('newslist')[0].get('content').replace('<br/>','\r\n')
    return result


#雷人笑话
def joke():
    url = 'http://api.tianapi.com/txapi/joke/index?key=%s'%key
    f = urllib.request.urlopen(url)
    resp = json.loads(f.read().decode('utf-8'))
    req = resp.get('newslist')[0].get('title')
    result = resp.get('newslist')[0].get('content')
    return req+ '\r\n'+result
